package jdk8.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;

import org.junit.Test;

interface MyComparable{
	// 返回大小
	boolean equals(int a,int b);
}

interface MyArray{
	// 传入一个数组，输出出来
	void print(int[] arr);
}

public class LambdaDemo2 {	
	
	@Test
	public void testPerson() {
		List<Person> list = new ArrayList<>();
		list.add(new Person(1,"zs"));
		list.add(new Person(8,"lisi"));
		list.add(new Person(4,"wangwu"));
		list.add(new Person(3,"maliu"));
		list.add(new Person(6,"zhaoqi"));
		
		System.out.println(list);
		
		// int compare(T o1, T o2);
		Comparator<Person> cp = (o1,o2)-> o2.getAge() - o1.getAge();
		
		// 根据人年纪从小到大排序
		Collections.sort(list,cp);
		System.out.println(list);
		
		// void accept(T t);
		Consumer<Person> c = (t) -> System.out.println(t);
		list.forEach(c);
	}
	
	

	@Test
	public void t1() {
		MyComparable mc = (a,b)-> a == b;
		boolean equals = mc.equals(10,10);
	}
	
	@Test
	public void t2() {
		MyArray a = (arr) -> System.out.println(Arrays.toString(arr));
		a.print(new int[] {1,2,3,4,5,6});
	}
}
